//
//  ECMainTabBarViewController.m
//  ERPChargeAccount2
//
//  Created by huanggulong on 2018/6/9.
//  Copyright © 2018年 历山大亚. All rights reserved.
//

#import "ECMainTabBarViewController.h"
#import "ECBaseItemModel.h"
#import "ECNavigationController.h"
#import "ECMainTabBar.h"
#import "ECOrderAddViewController.h"

@interface ECMainTabBarViewController ()

@property(nonatomic , strong)NSMutableArray *  dataArray;

@end

@implementation ECMainTabBarViewController

- (instancetype)init
{
    self = [super init];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    UINavigationBar *navigationBar = [UINavigationBar appearance];
    [navigationBar setTitleTextAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:19],NSForegroundColorAttributeName:@"#212121".toColor}];
    ECMainTabBar * tabBar = [ECMainTabBar new];
    [tabBar.centerBT addTarget:self action:@selector(centerBTAction:) forControlEvents:UIControlEventTouchUpInside];
    [self setValue:tabBar forKeyPath:@"tabBar"];
    [self loadViewControllers];
}

- (void)loadViewControllers{
    NSMutableArray *vcs = [NSMutableArray array];
    for (ECBaseItemModel *model in self.dataArray) {
        UIViewController *vc = [[model.destVC alloc] init];
        ECNavigationController *nav = [[ECNavigationController alloc] initWithRootViewController:vc];
        nav.tabBarItem = [[UITabBarItem alloc]initWithTitle:model.title image:[[UIImage imageNamed:model.normalImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:model.selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        vc.navigationItem.title = model.title;
        [vcs addObject:nav];
    }
    self.viewControllers = vcs;
}


- (NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        
        ECBaseItemModel *model1 = [ECBaseItemModel normalTitle:@"订单" icon:@"list_icon" selectedIcon:@"list_icon_pressed" destVC:@"ECOrderMainViewController"];//ECOrderAddViewController
        ECBaseItemModel *model2 = [ECBaseItemModel normalTitle:@"客户" icon:@"customer_icon" selectedIcon:@"customer_icon_pressed" destVC:@"ECMemberListViewController"];
        
        ECBaseItemModel *model3 = [ECBaseItemModel normalTitle:@"报表" icon:@"Form_icon" selectedIcon:@"Form_icon_pressed" destVC:@"ECOrderAddViewController"];
        ECBaseItemModel *model4 = [ECBaseItemModel normalTitle:@"我的" icon:@"Mine_icon" selectedIcon:@"Mine_icon_pressed" destVC:@"ECSelectCommodityViewController"];
        
        _dataArray = [NSMutableArray arrayWithObjects:model1,model2,model3,model4, nil];
    }
    return _dataArray;
}

- (void)centerBTAction:(UIButton*)sender {
    ECOrderAddViewController * vc = [ECOrderAddViewController new];
    [self presentViewController:vc animated:YES completion:nil];
}

@end
